Skip to content

[6.1] [SWT-0007] Introduce API allowing traits to customize test execution #907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

stmontgomery
Copy link
Contributor

…wiftlang#733)

This includes an API proposal and code changes to introduce new API for
custom traits to customize test execution.

View the [API
proposal](https://github.com/stmontgomery/swift-testing/blob/publicize-CustomExecutionTrait/Documentation/Proposals/NNNN-custom-test-execution-traits.md)
for more details.

One of the primary motivations for the trait system in Swift Testing, as
[described in the vision
document](https://github.com/swiftlang/swift-evolution/blob/main/visions/swift-testing.md#trait-extensibility),
is to provide a way to customize the behavior of tests which have things
in common. If all the tests in a given suite type need the same custom
behavior, `init` and/or `deinit` (if applicable) can be used today. But
if only _some_ of the tests in a suite need custom behavior, or tests
across different levels of the suite hierarchy need it, traits would be
a good place to encapsulate common logic since they can be applied
granularly per-test or per-suite. This aspect of the vision for traits
hasn't been realized yet, though: the `Trait` protocol does not offer a
way for a trait to customize the execution of the tests or suites it's
applied to.

Customizing a test's behavior typically means running code either before
or after it runs, or both. Consolidating common set-up and tear-down
logic allows each test function to be more succinct with less repetitive
boilerplate so it can focus on what makes it unique.

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
@stmontgomery stmontgomery added documentation 📚 Improvements or additions to documentation enhancement New feature or request public-api Affects public API api-proposal API proposal PRs (documentation only) labels Jan 13, 2025
@stmontgomery stmontgomery added this to the Swift 6.1 milestone Jan 13, 2025
@stmontgomery stmontgomery self-assigned this Jan 13, 2025
@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@stmontgomery stmontgomery merged commit 94e7873 into swiftlang:release/6.1 Jan 13, 2025
3 checks passed
@stmontgomery stmontgomery deleted the test-scoping-traits-6.1 branch January 13, 2025 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-proposal API proposal PRs (documentation only) documentation 📚 Improvements or additions to documentation enhancement New feature or request public-api Affects public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants